package cn.lili.modules.goods.serviceimpl;

import cn.lili.modules.goods.entity.dos.GoodsDownRecord;
import cn.lili.modules.goods.entity.dto.GoodsDownRecordDTO;
import cn.lili.modules.goods.mapper.GoodsDownRecordMapper;
import cn.lili.modules.goods.service.GoodsDownRecordService;
import cn.lili.modules.store.client.StoreClient;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

@Slf4j
@Service
@RequiredArgsConstructor
public class GoodsDownRecordServiceImpl extends ServiceImpl<GoodsDownRecordMapper, GoodsDownRecord>
        implements GoodsDownRecordService {


    /**
     * 运营中心-服务商-供货商家列表-商品下架详情页面
     *
     * @param dto
     * @return
     */
    @Override
    public Page<GoodsDownRecord> getSupplierByGoodsDownRecordPage(GoodsDownRecordDTO dto) {
        //查询本月
        if (dto.getQueryType() != null && dto.getQueryType() == 1) {
            LocalDateTime startOfMonth = LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0).withNano(0);
            dto.setStartTime(Date.from(startOfMonth.atZone(ZoneId.systemDefault()).toInstant()));
            dto.setEndTime(Date.from(startOfMonth.plusMonths(1).atZone(ZoneId.systemDefault()).toInstant()));
        }
        Page<GoodsDownRecord> page = baseMapper.selectPage(new Page<>(dto.getPageNumber(), dto.getPageSize()), dto.toQueryWarpper());
        return page;
    }
}
